﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using SalePartial.Utility;
using SalePartial.Model;
using System.Data;
using SalePartial.IDAL;

namespace SalePartial.SQLServerDAL
{

    //<DataObject(True)> _
    public class XPQuote : IXPQuote
    {
        // Methods
        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int Delete(Guid QuoteID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("QuoteID", QuoteID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuoteDelete]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByCompanyID(Guid CompanyID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesDeleteByCompanyID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByInquiryID(Guid InquiryID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("InquiryID", InquiryID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesDeleteByInquiryID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByUserID(Guid UserID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesDeleteByUserID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteDynamic(string v_whereCondition)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", v_whereCondition) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesDeleteDynamic]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Insert)> _
        public int Insert(XPQuoteInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("QuoteID", info.QuoteID),
			new SqlParameter("UserID", info.UserID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("InquiryID", info.InquiryID),
			new SqlParameter("QuoteApp", info.QuoteApp),
			new SqlParameter("QuoteStatus", info.QuoteStatus),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("CloseDate", info.CloseDate),
			new SqlParameter("DeleteDate", info.DeleteDate),
			new SqlParameter("SubmitDate", info.SubmitDate),
			new SqlParameter("LastSaveDate", info.LastSaveDate),
			new SqlParameter("ExpireDate", info.ExpireDate),
			new SqlParameter("UnitPriceByQty", info.UnitPriceByQty),
			new SqlParameter("CostOfDeliverByQty", info.CostOfDeliverByQty),
			new SqlParameter("OtherExpenseName", info.OtherExpenseName),
			new SqlParameter("OtherExpenseByQty", info.OtherExpenseByQty),
			new SqlParameter("TotalAmount", info.TotalAmount),
			new SqlParameter("Currency", info.Currency),
			new SqlParameter("DeliveryComment", info.DeliveryComment),
			new SqlParameter("Comment", info.Comment),
			new SqlParameter("Attachment", info.Attachment)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPQuoteInsert]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectAll()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesSelectAll]", parameters, "XPQuote_All");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesSelectByCompanyID]", parameters, "XPQuote_ByCompanyID");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectByInquiryID(Guid InquiryID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("InquiryID", InquiryID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesSelectByInquiryID]", parameters, "XPQuote_ByInquiryID");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectByUserID(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesSelectByUserID]", parameters, "XPQuote_ByUserID");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("WhereCondition", v_whereCondition),
			new SqlParameter("OrderByExpression", v_orderByExpression)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesSelectDynamic]", parameters, "XPQuote_Dynamic");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectPaged()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesSelectPaged]", parameters, "XPQuote_Paged");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReader(Guid QuoteID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("QuoteID", QuoteID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuoteSelect]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReaderByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesSelectByCompanyID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReaderByInquiryID(Guid InquiryID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("InquiryID", InquiryID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesSelectByInquiryID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReaderByUserID(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPQuotesSelectByUserID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectSingle(Guid QuoteID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("QuoteID", QuoteID) };
            DataSet ds = dbo.RunProcedure("[dbo].[xunpan_XPQuoteSelect]", parameters, "XPQuote_Single");
            DataTable dt = ds.Tables["XPQuote_Single"];
            return ds;
        }

        //<DataObjectMethod(DataObjectMethodType.Update)> _
        public int Update(XPQuoteInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("QuoteID", info.QuoteID),
			new SqlParameter("UserID", info.UserID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("InquiryID", info.InquiryID),
			new SqlParameter("QuoteApp", info.QuoteApp),
			new SqlParameter("QuoteStatus", info.QuoteStatus),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("CloseDate", info.CloseDate),
			new SqlParameter("DeleteDate", info.DeleteDate),
			new SqlParameter("SubmitDate", info.SubmitDate),
			new SqlParameter("LastSaveDate", info.LastSaveDate),
			new SqlParameter("ExpireDate", info.ExpireDate),
			new SqlParameter("UnitPriceByQty", info.UnitPriceByQty),
			new SqlParameter("CostOfDeliverByQty", info.CostOfDeliverByQty),
			new SqlParameter("OtherExpenseName", info.OtherExpenseName),
			new SqlParameter("OtherExpenseByQty", info.OtherExpenseByQty),
			new SqlParameter("TotalAmount", info.TotalAmount),
			new SqlParameter("Currency", info.Currency),
			new SqlParameter("DeliveryComment", info.DeliveryComment),
			new SqlParameter("Comment", info.Comment),
			new SqlParameter("Attachment", info.Attachment)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPQuoteUpdate]", parameters, RowsAffected);
        }

    }


}
